<?php
session_start();
include "include/db.php";

if (isset($_SESSION['user'])) 
    {
        header("Location: welcome.php");
    }
if(@$_POST['submit'])
    {

        $user = $_POST['username'];
        $pass = $_POST['password'];

        //echo "SELECT * FROM user WHERE user_name='$user' AND password='$pass' ";
        $query = "SELECT * FROM user WHERE user_name='$user' AND password='$pass' ";
        $sql = mysql_query($query);
        $row = mysql_num_rows($sql);
        if($row == 1)
            {
                $_SESSION['user'] = $user;
                header("Location: welcome.php");
            }
    }
?>
<!DOCTYPE HTML>
<html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Address Book</title>

    <!--- CSS --->
    <link rel="stylesheet" href="include/style.css" type="text/css" />
	<link rel="icon" type="image/png" href="include/images/favicon.png" />
    <script type='text/javascript'>

    function formValidator(){
    
	// Make quick references to our fields
	var user = document.getElementById('username').value;
	var pass = document.getElementById('password').value;
        
        if(user=='')
            {
                alert("Please enter username");
                user.focus();
                return false;
            }
         if(pass=='')
            {
                alert("Please enter password");
                pass.focus();
                return false;
            }
            
    }
    </script>

	

    </head>

<body>
    <div id="container">
	<form action="" name="frm" method="post" onSubmit="return formValidator()">
        <div class="login">LOGIN</div>
        	<div class="username-text">Username:</div>
		<div class="password-text">Password:</div>
		<div class="username-field">
		<input type="text" name="username" id="username" />
		</div>
		<div class="password-field">
		<input type="password" name="password" id="password"  />
		</div>
	        <div class="submit-button"><input type="submit" name="submit" value="GO" /></div>
	</form>
    </div>
<?php include "include/footer.php" ?>
</body>

</html>
